#ifndef TRANSFERTHREAD_H
#define TRANSFERTHREAD_H

#include <QThread>
#include <QMutex>
#include <QWaitCondition>

#include <QSerialPort>
#include <QFile>
#include <QTimer>

#include "settingsdialog.h"

#include "protocol/protocolymodem.h"

class TransferThread : public QThread
{
    Q_OBJECT

signals:
    void displayProgress(int progress);
    void transferOver(const QString &s, bool successed);


public:
    enum ProtocolType{
        ProtocolYMomde = 0,
    };

public:
    TransferThread(QObject *parent = nullptr);
    ~TransferThread();

    void startTrans();
    void stopTrans();

    void setDirection(Protocol::Direction _dir);
    void setFileName(const QString &name);
    void setProtocol(TransferThread::ProtocolType pro);
    void setSerialInfo(const SettingsDialog::Settings &serialSet);

private slots:
    void ymodemRun(void);


protected:
//    void run() override;

private:
    QString fileName;
    Protocol::Direction dir = Protocol::Transmit;
    ProtocolType protocol_type;


    QSerialPort *m_serial;
    QTimer *m_timer;

    ProtocolYModem *m_ymodem = nullptr;

};

#endif // TRANSFERTHREAD_H
